package com.hr.牛客网剑指offer;

import java.util.Stack;

/**
 * @author zhz
 * @date 2020/08/23
 **/
public class JZ15_反转链表 {
    /**
     * 利用栈的特点
     * @param head
     * @return
     */

    public ListNode ReverseList(ListNode head) {
        Stack<Integer> stack=new Stack<>();
        ListNode temp=head;
        while (temp!=null){
            stack.push(temp.val);
            temp=temp.next;
        }
        temp=head;
        while (!stack.isEmpty()){
            temp.val= stack.pop();
            temp=temp.next;
        }
        return head;
    }
    /*public ListNode ReverseList1(ListNode head) {

    }*/
}
